#!/bin/bash

# Flutter构建工具使用指南
# 用法: ./help.sh

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'

clear

echo -e "${CYAN}🚀 Flutter版本化构建工具 - 使用指南${NC}"
echo -e "${YELLOW}项目:${NC} playtruly (玩真的2 App)"
echo ""

# 获取当前版本信息
if [ -f "pubspec.yaml" ]; then
    VERSION=$(grep "^version:" pubspec.yaml | cut -d' ' -f2)
    echo -e "${YELLOW}当前版本:${NC} $VERSION"
else
    echo -e "${RED}⚠️  未找到pubspec.yaml文件，请确保在项目根目录执行${NC}"
fi

echo ""
echo -e "${BLUE}📋 可用命令列表${NC}"
echo ""

echo -e "${GREEN}🔍 版本管理${NC}"
echo -e "  ${CYAN}查看当前版本:${NC}     ./scripts/version_manager.sh show"
echo -e "  ${CYAN}升级补丁版本:${NC}     ./scripts/version_manager.sh bump patch"
echo -e "  ${CYAN}升级次版本:${NC}       ./scripts/version_manager.sh bump minor"
echo -e "  ${CYAN}升级主版本:${NC}       ./scripts/version_manager.sh bump major"
echo -e "  ${CYAN}升级构建号:${NC}       ./scripts/version_manager.sh bump build"
echo -e "  ${CYAN}设置指定版本:${NC}     ./scripts/version_manager.sh set 2.0.0 1"
echo ""

echo -e "${GREEN}📱 快速构建${NC}"
echo -e "  ${CYAN}构建Android APK:${NC}  ./scripts/quick_build.sh"
echo -e "  ${CYAN}构建调试版本:${NC}     ./scripts/quick_build.sh debug"
echo -e "  ${CYAN}构建发布版本:${NC}     ./scripts/quick_build.sh release"
echo ""

echo -e "${GREEN}🏗️ 单平台构建${NC}"
echo -e "  ${CYAN}Android:${NC}          ./scripts/build_with_version.sh android release"
echo -e "  ${CYAN}iOS:${NC}              ./scripts/build_with_version.sh ios release"
echo -e "  ${CYAN}Windows:${NC}          ./scripts/build_with_version.sh windows release"
echo -e "  ${CYAN}Web:${NC}              ./scripts/build_with_version.sh web release"
echo -e "  ${CYAN}macOS:${NC}            ./scripts/build_with_version.sh macos release"
echo -e "  ${CYAN}Linux:${NC}            ./scripts/build_with_version.sh linux release"
echo ""

echo -e "${GREEN}🚁 批量构建${NC}"
echo -e "  ${CYAN}构建所有平台:${NC}     ./scripts/build_all_platforms.sh"
echo -e "  ${CYAN}构建所有调试版:${NC}   ./scripts/build_all_platforms.sh debug"
echo -e "  ${CYAN}构建所有发布版:${NC}   ./scripts/build_all_platforms.sh release"
echo ""

echo -e "${GREEN}📚 帮助文档${NC}"
echo -e "  ${CYAN}显示此帮助:${NC}       ./scripts/help.sh"
echo -e "  ${CYAN}详细文档:${NC}         cat scripts/README.md"
echo ""

echo -e "${BLUE}💡 常用工作流程${NC}"
echo ""

echo -e "${PURPLE}🔄 开发调试流程:${NC}"
echo -e "  1️⃣  ./scripts/version_manager.sh show              # 查看当前版本"
echo -e "  2️⃣  ./scripts/quick_build.sh debug                 # 构建调试版本"
echo ""

echo -e "${PURPLE}🚀 版本发布流程:${NC}"
echo -e "  1️⃣  ./scripts/version_manager.sh bump patch        # 升级版本号"
echo -e "  2️⃣  ./scripts/build_all_platforms.sh release       # 构建所有平台"
echo -e "  3️⃣  # 手动测试和发布"
echo ""

echo -e "${PURPLE}⚡ 快速发布APK:${NC}"
echo -e "  1️⃣  ./scripts/version_manager.sh bump patch        # 升级版本号"
echo -e "  2️⃣  ./scripts/quick_build.sh release               # 构建发布版APK"
echo ""

echo -e "${BLUE}📂 输出文件${NC}"
echo -e "${YELLOW}构建文件保存在:${NC} builds/ 目录"
echo -e "${YELLOW}文件命名格式:${NC} playtruly_v{版本号}_{平台}_{类型}_{日期时间}.{扩展名}"
echo ""

echo -e "${BLUE}🛠️ 故障排除${NC}"
echo -e "  ${YELLOW}权限问题:${NC}         chmod +x scripts/*.sh"
echo -e "  ${YELLOW}Flutter环境:${NC}      flutter doctor"
echo -e "  ${YELLOW}清理构建:${NC}         flutter clean"
echo -e "  ${YELLOW}查看构建文件:${NC}     ls -la builds/"
echo ""

echo -e "${GREEN}✨ 开始使用吧！${NC}"